var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var MPage = require('../MPage.js');

Page(common.extendPage(MPage, {
	data: {
		dataLoaded: false,
		waiter: {},
	},

	onLoad(options) {

		this.techId = options.id || 1;

		this._getPageData();

	},

	_toMap(evt) {
		var shop = evt.currentTarget.dataset;

		ajax.G('/openapi/CAddress/getLocation', {
			addr: shop.address
		}, function(data) {
			var addressInfo = JSON.parse(data.result)['result'];

			wx.openLocation({
				latitude: addressInfo.location.lat,
				longitude: addressInfo.location.lng,
				name: shop.name,
				address: shop.address,
			})
		})
	},

	_getPageData() {
		var _self = this;

		ajax.P('/openapi/CTechnician/info', {
			technician_id: _self.techId
		}, function(data) {

			_self.setData({
				waiter: data.result.info,
				tagList: data.result.info.tags,
				dataLoaded: true,
			});

		});
	},

	_preview(evt) {
		var photos = this.data.waiter.photo;
		var cur = evt.currentTarget.dataset.url;

		wx.previewImage({
			current: cur,
			urls: photos
		})
	},

	//预约
	_appoint(evt) {
		wx.navigateTo({
			url: '/pages/appointOrder/appointOrder?techId=' + this.techId
		});
		common.submitForm(evt.detail.formId);
	},

}));